Red Hat Enterprise Linux Implementation

Network File Systems: Mounting

Module Topics

  • Network File System

  • NFS Mounting Methods

  • NFS Security Methods

  • nfs-secure

  • Mount an NFS Share

  • Automounter

  • Create an Automount

  • Direct Maps

  • Indirect Wildcard Maps

  • Connect to SMB Shares

  • Mount an SMB Share

  • Authentication to SMB Shares

  • Mount SMB Shares With Automounter

  • Mapping File

Network File System

  • NFS: Internet standard protocol used by Linux, UNIX, and similar operating systems as native network file system

    • Open standard under active extension

    • Supports native Linux permissions and file system features

  • Red Hat Enterprise Linux 7 supports NFSv4 by default

    • If v4 not available, falls back automatically to NFSv3 and NFSv2.

  • NFSv4 uses TCP to communicate with server

    • Older versions of NFS use either TCP or UDP

NFS Mounting Methods

  • NFS servers export shares (directories)

  • NFS clients mount exported share to local mount point (directory)

    • Local mount point must exist

  • NFS shares can be mounted in these ways:

    • Mount NFS share manually using mount

    • Mount NFS share automatically at boot using /etc/fstab

    • Mount NFS share on demand using automounting

NFS Security Methods

  • NFS server can offer single or multiple methods for each exported share

  • NFS clients must connect using methods mandated for that share

    • To specify mount option, use sec=method

none

Anonymous access to the files, writes to the server (if allowed) are allocated UID and GID of nfsnobody.

sys

File access based on standard Linux file permissions for UID and GID values. If not specified, this is the default.

krb5

Clients must prove identity using Kerberos and then standard Linux file permissions apply.

krb5i

Adds a cryptographically strong guarantee that the data in each request has not been tampered with.

krb5p

Adds encryption to all requests between the client and the server, preventing data exposure on the network. This will have a performance impact.

Kerberos options require, as a minimum, a /etc/krb5.keytab (provided by the authentication or security administrator) and additional authentication configuration (not covered here). Request a keytab that includes either a host principal, nfs principal, or (ideally) both.

nfs-secure

  • Negotiates and manages communication with server when connecting to Kerberos-secured shares

  • Must be running to use secured NFS shares

    • Start and enable to ensure it is always available:

      [student@desktop1 ~]$ sudo systemctl enable nfs-secure
      ln -s '/usr/lib/systemd/system/nfs-secure.service'  ...
      [student@desktop1 ~]$ sudo systemctl start nfs-secure
  • nfs-secure is part of nfs-utils package

    • Usually installed by default

    • To install manually, use:

      [student@desktop1 ~]$ sudo yum -y install nfs-utils

Mount an NFS Share

  1. Identify: Do one of the following:

    • Obtain export details and security requirements from NFS server admin

    • Identify NFSv4 shares by mounting root folder of NFS server and exploring exported directories as root

      • Denies access to shares using Kerberos security

      • Share (directory) name is visible

      • Other share directories are browsable

        [student@desktop1 ~]$ sudo mkdir /mountpoint
        [student@desktop1 ~]$ sudo mount server1:/ /mountpoint
        [student@desktop1 ~]$ sudo ls /mountpoint
    • Discover NFSv2 and NFSv3 shares using showmount

      [student@desktop1 ~]$ showmount -e server1
  2. Mount point: Use mkdir to create mount point in suitable location:

    [student@desktop1 ~]$ mkdir -p /mountpoint

Mount an NFS Share

  1. Mount: Switch to root or use sudo and do one of the following:

    • Manual: Use mount

      • To specify file system type for NFS shares, use -t nfs (not strictly required)

      • To synchronize write operations with NFS server, use -o sync (default is asynchronous)

        [student@desktop1 ~]$ sudo mount -t nfs -o sync server1:/share /mountpoint
    • /etc/fstab: Use vim to add mount entry to bottom of /etc/fstab

      • NFS share is mounted at each system boot

        [student@desktop1 ~]$ sudo vim /etc/fstab
        ...
        server1:/share  /mountpoint  nfs  sync  0 0
    • To manually unmount the share, use umount with root privileges

      [student@desktop1 ~]$ sudo umount /mountpoint
References
  • Man pages: mount(8), umount(8), fstab(5), and mount.nfs(8)

Automounter

  • autofs service managed like other system services

  • Can automatically mount NFS shares on demand

  • Automatically unmounts NFS shares when no longer used

  • Do not need root privileges to run mount or umount

    • NFS shares available to all users with access permissions

  • Frees network and system resources

    • Unlike entries in /etc/fstab, NFS shares are not permanently connected

  • No server-side configuration

  • Uses same mount options as mount

  • Flexible mount point locations

    • Direct and indirect mount point mapping

  • No need to manually manage indirect mount points

    • Created and removed by autofs

  • Can automount range of file systems (default=NFS)

Create an Automount

  1. Install autofs:

    [student@desktop1 ~]$ sudo yum -y install autofs
  2. Add master-map file to /etc/auto.master.d:

    • Identifies base directory for mount points

    • Identifies mapping file for creating automounts

      1. Use vim to create and edit master-map file:

        [student@desktop1 ~]$ sudo vim /etc/auto.master.d/demo.autofs
        • Must have .autofs extension

        • Can hold multiple mapping entries

        • Or, use multiple files to separate configuration data

      2. Add master-map entry to same or separate file:

        • For indirectly mapped mount points, add /shares /etc/auto.demo

          • All indirect map entries use /shares as base directory

          • /etc/auto.demo contains mount details

          • Create auto.demo before starting autofs

        • For directly mapped mount points, add /- /etc/auto.direct

          • All direct map entries use /- as base directory

          • /etc/auto.direct contains mount details

Create an Automount

  1. Create the mapping file(s) to identify mount point, mount options, and source location:

    1. Use vim to create and edit mapping file:

      [student@desktop1 ~]$ sudo vim /etc/auto.demo
      • Located in /etc and called auto.name (replace name with something meaningful)

    2. Add map entry:

      work  -rw,sync  server1:/shares/work
      • Entry format: mount point, mount options, source location

        • Mount point or key: Created and removed automatically by autofs

          • No need to align local mount point names and server directory structure

        • Mount options: Start with - (dash) and are comma-separated with no white space

          • Options available are same as manual mount

          • Useful automount-specific options:

            • Use fstype to specify the file system if it is not NFS

            • Use strict to treat errors, when mounting file systems, as fatal

        • Source location: NFS shares follow host:/pathname pattern

          • If file system to be mounted begins with / (slash), such as local device entries or SMB shares, then prefix with : (colon)

            • Example: SMB share would be ://server1/share.

Create an Automount

  1. Use systemctl to start and enable autofs:

    [student@desktop1 ~]$ sudo systemctl enable autofs
    ln -s '/usr/lib/systemd/system/autofs.service'  ...
    [student@desktop1 ~]$ sudo systemctl start autofs

Direct Maps

  • Map NFS share to existing mount point

  • Automounter will not attempt to create mount point automatically

    • Example: content for /etc/auto.direct might look like:

      /mnt/docs  -rw,sync  server1:/shares/docs
  • Mount point (or key) is always an absolute path

    • Starts with / (slash)

    • Rest of mapping file uses same structure

  • Only right-most directory under automounter control

    • Directory structure above mount point is not obscured by autofs

Indirect Wildcard Maps

  • Automounter can be configured to access any subdirectory exported by NFS server using single mapping entry

    • Example, if server1:/shares exports two or more subdirectories that are accessible with same mount options, then content for /etc/auto.demo might look like:

      *  -rw,sync  server1:/shares/&
    • Mount point (or key) is * (asterisk)

    • Subdirectory on source location is & (ampersand)

    • Everything else in entry is same as direct entry

References
  • Man pages: autofs(5), automount(8), auto.master(5), and mount.nfs(8)

Connect to SMB Shares

  • Red Hat Enterprise Linux uses Samba server to provide services Microsoft Windows clients can use

  • Samba implements SMB protocol

    • CIFS is dialect of SMB

  • Red Hat desktops and servers can connect to shares offered via any server that uses SMB protocol

    1. Identify remote share to access

    2. Determine mount point where share should be mounted and create mount point’s empty directory

    3. Mount network file system with appropriate command or configuration change

  • Before mounting SMB shares:

    • Install cifs-utils (required)

    • Install samba-client (optional)

Mount an SMB Share

  1. Identify: Do one of the following:

    • Obtain share details from SMB server host admin

    • Use client that can browse shares, such as smbclient

      [student@desktop1 ~]$ smbclient -L //server1
      • Use -L to list available shares

  2. Mount point: Use mkdir to create mount point in suitable location:

    [student@desktop1 ~]$ mkdir -p /mountpoint

Mount an SMB Share

  1. Mount: Switch to root or use sudo and do one of the following:

    • Manual: Use mount

      • To specify SMB as file system type, use -t cifs

      • To try and authenticate as guest account without password, use -o guest

        [student@desktop1 ~]$ sudo mount -t cifs -o guest //server1/share /mountpoint
    • /etc/fstab: Use vim to add mount entry to bottom of /etc/fstab

      [student@desktop1 ~]$ sudo vim /etc/fstab
      ...
      //server1/share  /mountpoint  cifs  guest  0 0
    • To manually unmount the share, use umount with root privileges

      [student@desktop1 ~]$ sudo umount /mountpoint

Authentication to SMB Shares

  • Can flag SMB shares as non-browsable

    • Clients such as smbclient will not display them

    • Can still access shares by explicitly specifying share name during mount

  • SMB servers typically restrict access to specific users, or groups of users

    • Must present credentials to SMB server to access protected shares

    • SMB server can use a wide range of authentication methods

    • Common authentication choice is username and password pairs

      • Can either be added to mount or /etc/fstab entry

      • Can be stored in credentials file referenced during mount

    • mount prompts for password if not provided

    • Password must be provided if using /etc/fstab

    • To explicitly request guest access, use guest

Authentication to SMB Shares

  • Example: Mount SMB share //server1/docs at /public/docs and attempt to authenticate as guest without password prompt

    [student@desktop1 ~]$ sudo mount -t cifs -o guest //server1/docs /public/docs
  • Example: Mount SMB share //server1/cases at /bakerst/cases and attempt to authenticate as watson with password prompt

    [student@desktop1 ~]$ sudo mount -t cifs -o username=watson //server1/cases /bakerst/cases
  • credentials offers better security

    • Stores password in more secure file than /etc/fstab which is easily examined

    • Place credentials somewhere with only root access, such as chmod 600

      • Example: Mount SMB share //server1/sherlock at home/sherlock/work and attempt to authenticate using credentials stored in /secure/sherlock

        [student@desktop1 ~]$ sudo mount -t cifs -o credentials=/secure/sherlock //server1/sherlock /home/sherlock/work
  • Credentials file format:

    username=username
    password=password
    domain=domain

Mount SMB Shares With Automounter

  • Can configure automounter (autofs) to mount SMB shares on demand

    • When process attempts to access file on SMB share

  • Automounter unmounts share after certain period of inactivity

  • Process to set up autofs on SMB share is essentially same as other automounts:

    1. If not already installed, install autofs

    2. Add auto.master.d configuration file

      • Identifies base directory for shares and mapping file

    3. Create or edit mapping file to include mount details for SMB share

    4. Enable and start autofs

Automounter depends on cifs-utils for mounting SMB shares

Mapping File

  • To specify file system type, use -fstype=cifs followed by comma-separated list of mount options

    • Use same options as mount

    • Prefix server URI address with a : (colon)

  • Example: Create an automount at /bakerst/cases for SMB share //server1/cases, and authenticate it against the /secure/sherlock credentials file

    • /etc/auto.master.d/bakerst.autofs content:

      /bakerst   /etc/auto.bakerst
    • /etc/auto.bakerst content:

      cases  -fstype=cifs,credentials=/secure/sherlock  ://server1/cases
    • /secure/sherlock content (owned by root, perms 600):

      username=sherlock
      password=violin221B
      domain=BAKERST
  • autofs enable and start:

    [student@desktop1 ~]$ sudo systemctl enable autofs
    [student@desktop1 ~]$ sudo systemctl start autofs
References
  • Man pages: mount(8), umount(8), fstab(5), mount.cifs(8), smbclient(1), autofs(5), automount(8), and auto.master(5)

Summary

  • Network File System

  • NFS Mounting Methods

  • NFS Security Methods

  • nfs-secure

  • Mount an NFS Share

  • Automounter

  • Create an Automount

  • Direct Maps

  • Indirect Wildcard Maps

  • Connect to SMB Shares

  • Mount an SMB Share

  • Authentication to SMB Shares

  • Mount SMB Shares With Automounter

  • Mapping File

Module Completion

Nice job!

Click the button below to complete this module of the course: